﻿#include "Shape.h"

IMPL_SERIAL(ShapeGroup, "XXShapeGroup")
IMPL_SERIAL(Circle, "XXCircle")
IMPL_SERIAL(Rectangle, "XXRectangle")

void ShapeGroup::Add(const std::shared_ptr<Shape>& shape)
{
    m_shapes.push_back(shape);
}

void ShapeGroup::Draw()
{
    for (auto& shape : m_shapes)
    {
        if (shape) shape->Draw();
    }
}

size_t ShapeGroup::WriteTo(COutputSerializer& ser) const
{
    auto begin = ser.Position();
    ser << m_shapes;
    return ser.Position() - begin;
}

size_t ShapeGroup::ReadFrom(CInputSerializer& ser)
{
    auto begin = ser.Position();
    m_shapes.clear();
    ser >> m_shapes;
    return ser.Position() - begin;
}

COutputSerializer& operator<<(COutputSerializer& ser, const Header& header)
{
    ser << header.version;
    return ser;
}
CInputSerializer& operator>>(CInputSerializer& ser, Header& header)
{
    ser >> header.version;
    return ser;
}

